export default {
    namespaced: true,
    state: {
      cartTotal:0,
      userInfo:{
          nickName:"昵称",
          coin:10,
          headImg:"头像"
      }
    },
    getters: {

    },
    mutations: {
        changeUserInfo(state,payload){
            state.cartTotal=payload.cartTotal,
            state.userInfo=payload.userInfo
        },
          //初始化用户信息
          initUserInfo(state) {
            state.cartTotal = 0;
            state.userInfo = {
                //昵称
                nickName: '昵称',
                //积分
                coin: 1000,
                //用户头像
                headImg: require('../../assets/img/service.848ec511.png')
            }
        }
       
    },
    actions: {
        async asyncChangeUserInfo({ commit }, payload) {
            //获取用户信息(异步)
            let res = await UserProfilesAPI();
            // console.log("用户信息为", res);
            //更新vuex中用户数据(触发mutaions)
            commit('updateUserInfo', res.data);
        }
    },
}